﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SqlImEx.Util
{
    public static class ExtensionMethods
    {
        public static string DelimitedString<T>(this IEnumerable<T> instance, Func<T, string> value, string delimiter)
        {
            var sb = new StringBuilder();
            foreach (var l in instance)
            {
                sb.Append(value(l));
                if (Array.IndexOf(instance.ToArray(), l) != instance.Count() - 1)
                    sb.Append(delimiter);
            }
            return sb.ToString();
        }
        public static bool IsLast<T>(this IEnumerable<T> instance, T item)
        {
            return Array.IndexOf(instance.ToArray(), item) == instance.ToArray().Length - 1;
        }
        public static bool IsFirst<T>(this IEnumerable<T> instance, T item)
        {
            return Array.IndexOf(instance.ToArray(), item) == 0;
        }
    }
}
